package it.webrules.deploymanager.core.dy;

import it.webrules.deploymanager.core.condition.ConditionEngine;
import it.webrules.deploymanager.core.dy.deploy.MBeanManager;
import it.webrules.xsd.dmc.config.v1.Condition;

public class DeployConditionEngine extends ConditionEngine {

	private final MBeanManager mbeanManager;

	public DeployConditionEngine(MBeanManager mbeanManager) {
		this.mbeanManager = mbeanManager;
	}

	protected Object getMBeanValue(Condition condition) throws Exception {

		String mbeanComposedName = condition.getName();

		String[] mbean = mbeanComposedName.split(";");

		Object value = null;
		if (mbean.length == 3)
			value = mbeanManager.getMBeanValue(mbean[0], mbean[1], mbean[2]);
		else if (mbean.length == 2)
			value = mbeanManager.getMBeanValue(mbean[0], mbean[1]);
		else {
			logger.warn("Bad MBean reference name, {}.", mbeanComposedName);
		}

		return value;

	}

}
